package com.cyx;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @author 陈裕星
 * @version 1.0
 */
public class 括号生成之回溯 {
    static int n;
    static List<String> res = new ArrayList<>();
    static StringBuilder sb = new StringBuilder();
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();

        recursive(0,0);

        System.out.println(res.toString());
    }

    /**
     *
     * @param left:左括号个数
     * @param right：右括号个数
     */
    static void recursive(int left,int right){
        //推出条件
        if (left == n && right == n){
            res.add(sb.toString());
            return;
        }

        //剪枝
        if(right > left || left > n) return;

        sb.append("(");
        //递归
        recursive(left + 1,right);
        //回溯
        sb.deleteCharAt(sb.length()-1);

        sb.append(")");
        //递归
        recursive(left,right + 1);
        //回溯
        sb.deleteCharAt(sb.length()-1);

    }
}
